﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace calculator
{
    public partial class Form1 : Form
    {
        double number1 = 0;
        double number2 = 0;
        double resultNumber = 0;

        public Form1()
        {
            InitializeComponent();
        }

        #region  数字1-9
        private void Btnnumber0_Click(object sender, EventArgs e)
        {
            if (lbdisplay.Text != "0")
            {
                lbdisplay.Text += "0";
            }
            lbdisplay.Refresh();
        }

        private void Btnnumber1_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "1";
            }
            else
            {
                lbdisplay.Text += "1";
            }
        }

        private void Btnnumber2_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "2";
            }
            else
            {
                lbdisplay.Text += "2";
            }
        }

        private void Btnnumber3_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "3";
            }
            else
            {
                lbdisplay.Text += "3";
            }
        }

        private void Btnnumber4_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "4";
            }
            else
            {
                lbdisplay.Text += "4";
            }
        }

        private void Btnnumber5_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "5";
            }
            else
            {
                lbdisplay.Text += "5";
            }
        }

        private void Btnnumber6_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "6";
            }
            else
            {
                lbdisplay.Text += "6";
            }
        }

        private void Btnnumber7_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "7";
            }
            else
            {
                lbdisplay.Text += "7";
            }
        }

        private void Btnnumber8_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "8";
            }
            else
            {
                lbdisplay.Text += "8";
            }
        }

        private void Btnnumber9_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text == "0")
            {
                lbdisplay.Text = "9";
            }
            else
            {
                lbdisplay.Text += "9";
            }
        }



        #endregion

        /// <summary>
        /// 小数点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btndoc_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Text.Contains("."))
            {

            }
            else
            {
                lbdisplay.Text += ".";
            }
            lbdisplay.Refresh();

        }
        /// <summary>
        /// 清空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btnnull_Click(object sender, EventArgs e)
        {
            lbdisplay.Text = "0";
            number1 = 0;
            number2 = 0;
            resultNumber = 0;
            lbdisplay.Tag = "0";
            lbdisplay.Refresh();
        }
        /// <summary>
        /// 等于
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btnend_Click_1(object sender, EventArgs e)
        {
            number2 = Convert.ToDouble(lbdisplay.Text);
            switch (lbdisplay.Tag)
            {
                case "+":
                    resultNumber = number1 + number2;
                    break;
                case "-":
                    resultNumber = number1 - number2;
                    break;
                case "*":
                    resultNumber = number1 * number2;
                    break;
                case "/":
                    resultNumber = number1 / number2;
                    break;
            }
            lbdisplay.Text = $"{resultNumber}";
            number1 = 0;
            number2 = 0;
            lbdisplay.Tag = "0";
            lbdisplay.Refresh();
        }

        public void end()
        {
            number2 = Convert.ToDouble(lbdisplay.Text);
            switch (lbdisplay.Tag)
            {
                case "+":
                    resultNumber = number1 + number2;
                    break;
                case "-":
                    resultNumber = number1 - number2;
                    break;
                case "*":
                    resultNumber = number1 * number2;
                    break;
                case "/":
                    resultNumber = number1 / number2;
                    break;
            }
            lbdisplay.Text = "0";
            //lbdisplay.Text = $"{resultNumber}";
            number1 = resultNumber;
            number2 = 0;
            lbdisplay.Refresh();
        }

        #region  加减乘除
        private void Btnplus_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Tag.ToString() == "0")
            {
                number1 = Convert.ToDouble(lbdisplay.Text);
                lbdisplay.Text = "0";
                lbdisplay.Tag = "+";
            }
            else
            {
                end();
            }
            lbdisplay.Refresh();
        }

        #endregion


        private void Btnride_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Tag.ToString() == "0")
            {
                number1 = Convert.ToDouble(lbdisplay.Text);
                lbdisplay.Text = "0";
                lbdisplay.Tag = "*";
            }
            else
            {
                end();
            }
        }

        private void Btnexcept_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Tag.ToString() == "0")
            {
                number1 = Convert.ToDouble(lbdisplay.Text);
                lbdisplay.Text = "0";
                lbdisplay.Tag = "/";
            }
            else
            {
                end();
            }
        }

        private void Btnreduce_Click_1(object sender, EventArgs e)
        {
            if (lbdisplay.Tag.ToString() == "0")
            {
                number1 = Convert.ToDouble(lbdisplay.Text);
                lbdisplay.Text = "0";
                lbdisplay.Tag = "-";
            }
            else
            {
                end();
            }
        }
    }
}
